package progress.exa35;

import java.io.*;

/**
 * 检查型异常学习
 */
public class CheckedException {

    public static void main(String[] args) {
        try {
            IoException2();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        System.out.println("程序正常结束！！");

    }

    /**
     * 这个方法将在发生IOException异常将其抛出,在发生类加载异常时将其抛出
     **/
    public static void IoException1() throws IOException, ClassNotFoundException {
        File file = new File("noEx");
        InputStream inputStream = new FileInputStream(file);
        inputStream.read();
        Class cl = Class.forName("java");
    }

    /**
     * 抛出异常
     */
    public static void IoException2() throws IOException, ClassNotFoundException {
        File file = new File("noEx");
        try {
            InputStream inputStream = new FileInputStream(file);
            inputStream.read();
        }catch (FileNotFoundException fileNotFoundException){
            throw new FileNotFoundException("未找到文件");
        }catch (IOException e){
            e.printStackTrace();
            throw new IOException("文件读取");
        }

        try {
            Class cl = Class.forName("java");
        }catch (ClassNotFoundException e){
            throw new ClassNotFoundException("未找到类文件java.class");
        }

    }


}
